import React from "react";
import {Tag} from "antd";
import {OutboundDeliveryOrder} from "type/OutboundDeliveryOrder";

import {OTHER, RETURN, SALE, SERVICE, TRANSFER} from "./constant";
import {OdoTypeKey} from "./init";

/**
 * 出库单处理类
 */
class OdoHandler{
    private static readonly ODO_TYPE_TAG = new Map<OdoTypeKey,React.ReactNode>();
    private static readonly instance = new OdoHandler();
    private constructor() {
        OdoHandler.ODO_TYPE_TAG.set(SALE,<Tag color={"#1f5b16"}>销售</Tag>);
        OdoHandler.ODO_TYPE_TAG.set(SERVICE,<Tag color={"#0d5e5b"}>服务</Tag>);
        OdoHandler.ODO_TYPE_TAG.set(TRANSFER,<Tag color={"#720a64"}>调拨</Tag>);
        OdoHandler.ODO_TYPE_TAG.set(RETURN,<Tag color={"#482525"}>返货</Tag>);
        OdoHandler.ODO_TYPE_TAG.set(OTHER,<Tag color={"#2a1c5e"}>其他</Tag>);
    }
    public static getInstance(): OdoHandler {
        return this.instance;
    }

    public odoTypeRender = (value: OdoTypeKey): React.ReactNode => {
        return OdoHandler.ODO_TYPE_TAG.get(value) ;
    } ;

    public odoFlowRender = (value: string, record: OutboundDeliveryOrder ): React.ReactNode => {
        if (record.odoType === SALE){
            return value ;
        }
        return value + "*" ;
    } ;

}
export default OdoHandler;